Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix misleading sentence in http.md #26465

Closed
wants to merge 1 commit into from
Closed

Conversation

lpinca
Copy link
Member

@lpinca lpinca commented Mar 6, 2019

Calling response.end(data) is not 100% equivalent to calling
response.write(data) followed by response.end().

Fixes: #26005

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. http Issues or PRs related to the http subsystem. labels Mar 6, 2019
BridgeAR
BridgeAR previously approved these changes Mar 6, 2019
@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 6, 2019
doc/api/http.md Outdated
[`response.write(data, encoding)`][] followed by `response.end(callback)`. There
is, however, a difference in the headers that are sent by default. If
[`response.write()`][] is used, the `Transfer-Encoding` header is set to
`chunked`, otherwise the `Transfer-Encoding` header is replaced by the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
`chunked`, otherwise the `Transfer-Encoding` header is replaced by the
`'chunked'`, otherwise the `Transfer-Encoding` header is replaced by the

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional suggestion: Change the comma to a period and make the Otherwise clause its own sentence.

@richardlau
Copy link
Member

Commit message has misspelled sentence.

doc/api/http.md Outdated
is, however, a difference in the headers that are sent by default. If
[`response.write()`][] is used, the `Transfer-Encoding` header is set to
`'chunked'`. Otherwise the `Transfer-Encoding` header is replaced by the
`Content-Length` header.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this leaves one case undescribed: response.write(data); response.end(data)

Also, while accurate, so an improvement, I think its too low level, it doesn't give any idea why its done this way. And if you knew why, then you wouldn't need the docs.

I'd suggest that the .write() docs be modified to say that because .write() can be called multiple times, the size of the entire response (or request, I suspect these docs apply to both req and response) cannot be known when .write() is called, so HTTP will use chunked transfer encoding, and there will not be a content-size header.

In .end(), I'd say that if .write() has not previously been called, the total size is known (zero, or the size of the data arg), so node.js doesn't have to (and won't) use chunked transfer encoding, and it will write a content-length header. In other cases, since chunked transfer has already begun, any data provided to .end() will be transferred as a chunk.

^--- I think this is accurate, and describes why this is, and makes this seem less like a weird gotcha, and more like a feature: that if you have one large chunk that can be written in a single call to .end(), you can cause the content-size to be set and chunked mode not to be used. I'm not sure if it applies equally to the writing of requests, and the writing of responponses... but it should!

Copy link
Member Author

@lpinca lpinca Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only wanted to address the misleading sentence quoted in #26005 and not describe chunk mode. This is also not 100% accurate as the user could explicitly specify Content-Length disabling the default chunked mode. Perhaps it's simpler to just remove that sentence?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have the info about how explicitly setting the header changes things. Basically, that Node.js has good support for chunked mode (unlike a number of crappy HTTP APIs I've come across), is a wonderful feature, its a shame we don't document it better.

Your comment above makes me wonder if your proposed text is accurate/complete, doesn't it suffer the same problem?

For now, yes, I think rather than dumping in the detail you proposed, if you aren't up to a really comprehensive treatment, just changing "the same as" to "similar in effect to", or similar weasel words, might make the docs "not wrong", even though it still leaves streaming vs non-streaming mode undoced.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment above makes me wonder if your proposed text is accurate/complete, doesn't it suffer the same problem?

Yes, I've added "the headers that are sent by default" to address that but I guess it's not clear.

I will change this tomorrow and use "similar" removing all the chunked mode info.
FWIW the request counterparts are slightly better documented.

@sam-github sam-github changed the title doc: fix misleading sentece in http.md doc: fix misleading sentence in http.md Mar 6, 2019
@sam-github
Copy link
Contributor

nit: I think a commit message of doc: describe when chunked mode is used would be more descriptive of the specific change being made.

Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

Fixes: nodejs#26005
@lpinca
Copy link
Member Author

lpinca commented Mar 7, 2019

Folks that approved this, PTAL, I've updated as per @sam-github suggestion.

@BridgeAR
Copy link
Member

BridgeAR commented Mar 7, 2019

I would rather have a detailed information but I won't block this either.

@lpinca
Copy link
Member Author

lpinca commented Mar 7, 2019

It makes sense but I don't have the energy to update the docs as suggested in #26465 (comment) explaining how and when chunked mode is used, how to disable it, etc. especially due to all the nit picking that will come from that.

If that is preferred I would prefer it to be done by a native speaker.

@BridgeAR
Copy link
Member

What should be done here?

@jasnell PTAL

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Mar 13, 2019
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: nodejs#26465
Fixes: nodejs#26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
@BridgeAR
Copy link
Member

Landed in 1706a2d 🎉

@BridgeAR BridgeAR closed this Mar 13, 2019
@lpinca lpinca deleted the gh-26005 branch March 13, 2019 15:47
BridgeAR pushed a commit that referenced this pull request Mar 14, 2019
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: #26465
Fixes: #26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Mar 14, 2019
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: nodejs#26465
Fixes: nodejs#26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
BridgeAR pushed a commit that referenced this pull request Mar 14, 2019
Calling `response.end(data)` is not 100% equivalent to calling
`response.write(data)` followed by `response.end()`.

PR-URL: #26465
Fixes: #26005
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doc(http): res.write(data) followed by res.end() is not actually equivalent to res.end(data)
9 participants